package com.parfinex.part1;

public class Employee {
    //自定义私有的成员变量
    private String name;
    private int age;

    public Employee() {
    }

    public Employee(String name, int age) {
        setName(name);
        setAge(age);
    }
//提供公有的get和get方法

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.equals("")){
            try {
                throw new NameException("姓名不能为空");
            } catch (NameException e) {
                e.printStackTrace();
            }
        }
        if (null != name){
            System.out.println(name.equals(""));
                this.name = name;
        } else {
            try {
                throw new NameException("姓名不能为NULL");
            } catch (NameException e) {
                e.printStackTrace();
            }
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age> 0 && age<150) {
            this.age = age;
        } else {
            try {
                throw new AgeException("年龄不合理哦！");
            } catch (AgeException e) {
                e.printStackTrace();
            }
        }

    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
